﻿Namespace AboutDNN.DNNMVC

    Public Class BaseRouteHandler
        Implements System.Web.IHttpHandler

        Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
            Try
                ' Init MVC
                App.InitMVC()

                ' Execute the action
                Dim result = RouteHelper.ExecuteAction()

                ' Process the result
                ProcessResult(result)

            Catch ex As Exception
                App.HandleException(ex)
            End Try
        End Sub

        Private Sub ProcessResult(ByVal result As ActionResult)
            Select Case result.Type
                Case ActionResult.ActionTypeEnum.View
                    RouteHelper.RenderView(result.ViewPath, result.Data)

                Case ActionResult.ActionTypeEnum.Literal
                    RouteHelper.RenderLiteral(result.Data)

                Case ActionResult.ActionTypeEnum.Json
                    RouteHelper.RenderJson(result.Data)

            End Select
        End Sub

        Public ReadOnly Property IsReusable As Boolean Implements System.Web.IHttpHandler.IsReusable
            Get
                Return False
            End Get
        End Property

    End Class

End Namespace
